// ignore_for_file: file_names, slash_for_doc_comments, must_call_super, unnecessary_overrides, override_on_non_overriding_member, must_be_immutable, prefer_const_constructors


import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mybase/base/abstract/IFFR.dart';
import 'package:mybase/base/abstract/IFFRefresh.dart';
import 'package:mybase/base/abstract/IFFScaffold.dart';
import 'package:mybase/base/tool/arouter/FFGoto.dart';
import 'package:mybase/base/widget/layout/FFLineContainer.dart';
import 'package:mybase/base/widget/layout/FFNavi.dart';
import 'package:mybase/base/widget/layout/FFTextButton.dart';
import 'package:mybase/base/widget/page/FFListScaffold.dart';
import 'package:mybase_example/demos/animator/Animator2Page.dart';
import 'package:mybase_example/demos/animator/AnimatorPage.dart';
import 'package:mybase_example/demos/response/ResponsePage.dart';
import 'package:mybase_example/typedef/CustomType.dart';

class HomePage extends FFListScaffold {
  String? name;

  HomePage({
    Key? key,
    this.name,
  }) : super(key: key);

  @override
  HomePageState createState() => HomePageState();
}

class HomePageState extends FFListScaffoldState {
  /**固定写法 */
  @override
  IFFScaffold get iffScaffold => this;

  @override
  HomePage get widget => super.widget as HomePage;

  ///刷新控制
  @override
  IFFRefresh? get iffRefresh => refresh;
  late HomePageStateRefresh refresh = HomePageStateRefresh(state: this);

  @override
  FFPageSpacingParam? get ffPageSpacingParam => FFPageSpacingParam(bottomSpacing: true);

  /**固定写法end */

  @override
  void ffInitState() {
    super.ffInitState();
  }

  @override
  Widget? ffNavi(BuildContext context) {
    return FFNaviFast.navi(context, "测试各种情况",
        color: Colors.white, haveLeading: false);
  }

  @override
  Widget ffItem(BuildContext context, int index) {
    IListEntity iListEntity = datas[index];
    return FFLineContainer(
      direction: Axis.horizontal,
      padding: EdgeInsets.symmetric(horizontal: 16.w,vertical: 16.w),
      margin: EdgeInsets.only(top: 10.w),
      color: Colors.pink.withAlpha(100),
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      onClick: iListEntity.getClick(),
      children: [
        FFTextButton(
          text: iListEntity.getTitle(),
        ),
        FFTextButton(
          text: iListEntity.getSubTitle(),
        ),
      ],
    );
  }
}

///自定义刷新
class HomePageStateRefresh with MFFRefresh {
  HomePageState state;

  HomePageStateRefresh({required this.state});

  @override
  ffRefresh(bool isHead) {
    ffRefreshResult(isHead, test, state);
  }

  Future<IFFR> test(IRefreshParam? iRefreshParam) async {
    List<IListEntity> list = [];

    list.add(HomeListEntity(
        title: "响应式",
        subTitle: "ResponsePage",
        onClick: () {
          FFGoto.gotoPage(state.context, ResponsePage());
        }));

    list.add(HomeListEntity(
        title: "动画",
        subTitle: "AnimatorPage",
        onClick: () {
          FFGoto.gotoPage(state.context, AnimatorPage());
        }));

    list.add(HomeListEntity(
        title: "动画",
        subTitle: "AnimatorPage2",
        onClick: () {
          FFGoto.gotoPage(state.context,Animator2Page());
        }));

    return R(rStatus: RStatus.result, data: list);
  }
}

///下面所有的Entity代码均可放在其他文件，这儿为了方便，写在这儿
///抽象类
abstract class IListEntity {
  String? getTitle();
  String? getSubTitle();

  Click? getClick();
}

///实现抽象类的base类，方便抽象类添加方法
class BaseListEntity implements IListEntity {
  @override
  String? getTitle() {}

  @override
  Click? getClick() {}

  @override
  String? getSubTitle() {}
}


class HomeListEntity with BaseListEntity {
  String? title;
  String? subTitle;
  Click? onClick;

  HomeListEntity({
    this.title,
    this.subTitle,
    this.onClick,
  });

  @override
  String? getTitle() {
    return title;
  }

  @override
  Click? getClick() {
    return onClick;
  }

  @override
  String? getSubTitle() {
    return subTitle;
  }
}
